package com.yn.xgame.message;

import com.yn.xgame.IServer;

import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * 先执行supplier函数，然后将结果放到consumeServer上，用consumer函数执行
 * Created by wangboo on 2017/7/11.
 */
public class SupplyAndConsumeMessage<R> implements IFuncMessage {

    private Supplier<R> supplier;
    private Consumer<R> consumer;
    private IServer consumeServer;

    public SupplyAndConsumeMessage(IServer consumeServer, Supplier<R> supplier, Consumer<R> consumer) {
        this.consumeServer = consumeServer;
        this.supplier = supplier;
        this.consumer = consumer;
    }

    @Override
    public void apply() {
        R r = supplier.get();
        Func1Message<R> func = new Func1Message<>(r, consumer);
        consumeServer.pushMessage(func);
    }
}
